package Connector;

import java.io.File;

public class ConnectorUtils {

    public static final String WEB_ROOT = System.getProperty("user.dir") + File.separator + "webroot";
    // TODO getProperty("user.dir")是干嘛的???
        // 可以得到当前程序的目录
        // https://www.dazhuanlan.com/zhyagao/topics/1478922


    public static final String  PROTOCOL = "HTTP/1.1";

    public static final String CARRIGE = "\r";

    public static final String NEWLINE = "\n";

    public static final String SPACE = " ";

    /*
    HTTP/1.1 200 OK
     */
    // 根据HTTP状态，拼接状态行
    public static String renderStatus(HttpStatus status){
        System.out.println("ConnectorUtils is generating the status line...");
        StringBuilder statusLine = new StringBuilder(PROTOCOL)
                .append(SPACE)
                .append(status.getStatusCode())
                .append(SPACE)
                .append(status.getReason())
                .append(CARRIGE).append(NEWLINE)
                .append(CARRIGE).append(NEWLINE);
        // TODO \r\n\r\n ???
            // 是HTTP头部字段和消息正文的分割
            // 两次换行才是一个空行
        return statusLine.toString();
    }
}
